package org.core.blog.controller;

import lombok.extern.slf4j.Slf4j;
import org.core.blog.pojo.LoginInfo;
import org.core.blog.pojo.Result;
import org.core.blog.pojo.User;
import org.core.blog.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/auth")
    public Result login(@RequestBody User user){
        log.info("用户登录：{}", user);
        LoginInfo info=loginService.login(user);
        if(info!=null) return Result.success(info);
        else return Result.error("登录失败");
    }
}
